<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<!DOCTYPE html>
<html>
<head>
    <title>账户信息管理（药品采购中心端）</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <style type="text/css">
        div.group-info {
            margin-top: 10px !important;
            margin-bottom: 0px !important;
        }
    </style>
</head>
<body class="skin-blue sidebar-mini fixed skin-blue-light-frame">
    <c:set var="type" value="${bankAcctInfo != null and bankAcctInfo.auditStatus == 1}"></c:set>
    <section class="content-header">
        <h1>账户信息管理</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">账户信息管理</a></li>
        </ol>
     </section>
     
     <section class="content" style="min-height:inherit;">
        <div class=" box box-success ">
          <form class="form-horizontal"  method="post">
            <input type="hidden" id="orgId" name="orgId" value="${setAcctInfo.orgId}" />
            
            <div class="box-body">
               <div class="form-group form-group-xs group-info">
                     <label for="inputTextAlter1" class="col-sm-2 text-right">机构编号：</label>
                     <div class="col-sm-4 text-left" >${setAcctInfo.orgCode}</div>
                     <label for="inputTextAlter2" class="col-sm-2 text-right">机构名称：</label>
                     <div class="col-sm-4 text-left">${setAcctInfo.orgName}</div>
                </div>
                 
                <div class="form-group form-group-xs group-info">
                     <label for="inputTextAlter2" class="col-sm-2 text-right">账户余额：</label>
                     <div class="col-sm-4 text-left">${setAcctInfo.outstandAmtStr}</div>
                     <label for="inputTextAlter1" class="col-sm-2 text-right">可用余额：</label>
                     <div class="col-sm-4 text-left">${setAcctInfo.availableAmtStr}</div>
                </div>
                
                <div class="form-group form-group-xs group-info">
                     <label for="inputTextAlter2" class="col-sm-2 text-right">待结算金额：</label>
                     <div class="col-sm-4 text-left">${setAcctInfo.pendingAmtStr}</div>
                </div> 
            </div>
        </form>
        </div>
     </section>
      <section class="content">
        <div class=" box box-primary ">
            <form id="form" class="form-horizontal" action="${ctx}/acctInfo/saveBankAcctInfo.html" method="post" enctype="multipart/form-data" >
                <input type="hidden" id="bankAcctId" name="bankAcctId" value="${bankAcctInfo.bankAcctId}" />
                
                <div class="box-body">
                    <div class="form-group form-group-xs">
                        <label for="bankAcctNo" class="col-sm-2 text-right"><c:if test="${!type}"><span class="required">*</span></c:if>银行账号：</label>
                        <div class="col-sm-4 text-left">
                            <c:if test="${type}">
                                ${bankAcctInfo.bankAcctNo}
                            </c:if>
                            <c:if test="${!type}">
                                <input class="form-control" id="bankAcctNo" name="bankAcctNo" value="${bankAcctInfo.bankAcctNo}" placeholder="银行账号" type="text" maxlength="36">
                            </c:if>
                        </div>
                        <label for="acctHolder" class="col-sm-2 text-right"><c:if test="${!type}"><span class="required">*</span></c:if>开户人：</label>
                        <div class="col-sm-4 text-left">
                            <c:if test="${type}">
                                ${bankAcctInfo.acctHolder}
                            </c:if>
                            <c:if test="${!type}">
                                <input class="form-control" id="acctHolder" name="acctHolder" value="${bankAcctInfo.acctHolder}" placeholder="开户人" type="text" maxlength="128">
                            </c:if>
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="depositBank" class="col-sm-2 text-right"><c:if test="${!type}"><span class="required">*</span></c:if>开户行：</label>
                        <div class="col-sm-4 text-left">
                            <c:if test="${type}">
                                ${bankAcctInfo.depositBank}
                            </c:if>
                            <c:if test="${!type}">
                                <select class="form-control" id="depositBank" name="depositBank">
                                    <option value="">请选择</option>
                                    <c:if test="${ bankList != null }">
                                        <c:forEach items="${bankList}" var="item">
                                            <option value="${item.bankAcctNo}" ${bankAcctInfo.depositBank == item.bankAcctNo ? "selected='selected'" : ""}>${item.fatherBankName}</option>
                                        </c:forEach>
                                    </c:if>
                                </select>
                            </c:if>
                        </div>
                         <label for="acctApprovalPicDir" class="col-sm-2 text-right"><c:if test="${!type}"><span class="required">*</span></c:if>开户许可证：</label>
                        <div class="col-sm-4 text-left">
                            <c:if test="${type}">
                                <a href="javascript:showImg('${bankAcctInfo.acctApprovalPicDir}');" style="display:inline-block;">查看</a>
                            </c:if>
                            <c:if test="${!type}">
                                <div style="width:0px;height:0px;overflow:hidden;">
                                    <input id="acctApprovalPicDir" name="licence" type="file" style="display:inline-block;" />
                                </div>
                                <a href="javascript:selectImg();" style="display:inline-block;">上传</a>
                                <c:if test="${bankAcctInfo != null && bankAcctInfo.acctApprovalPicDir != null}">
                                    <a href="javascript:showImg('${bankAcctInfo.acctApprovalPicDir}');" style="display:inline-block;">查看</a>
                                </c:if>
                            </c:if>
                        </div>
                        
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="depositBankNo" class="col-sm-2 text-right"><c:if test="${!type}"><span class="required">*</span></c:if>开户行行号：</label>
                        <div class="col-sm-4 text-left">
                            <c:if test="${type}">
                                ${bankAcctInfo.depositBankNo}
                            </c:if>
                            <c:if test="${!type}">
                                <input onclick="bank();"  class="form-control" id="depositBankNo" name="depositBankNo" value="${bankAcctInfo.depositBankNo}" placeholder="开户行号" type="text" maxlength="128" >
                            </c:if>
                        </div>
                        <label for="depositBankName" class="col-sm-2 text-right"><c:if test="${!type}"><span class="required">*</span></c:if>开户行行名：</label>
                        <div class="col-sm-4 text-left">
                            <c:if test="${type}">
                                ${bankAcctInfo.depositBankName}
                            </c:if>
                            <c:if test="${!type}">
                                <input onclick="bank();" class="form-control" id="depositBankName" name="depositBankName" value="${bankAcctInfo.depositBankName}" placeholder="开户行名" type="text" maxlength="128">
                            </c:if>
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="depositBankAreaName" class="col-sm-2 text-right"><c:if test="${!type}"><span class="required">*</span></c:if>开户行区域：</label>
                        <div class="col-sm-4 text-left">
                            <c:if test="${type}">
                                ${bankAcctInfo.depositBankAreaName}
                            </c:if>
                            <c:if test="${!type}">
                                <input onclick="bank();" class="form-control" id="depositBankAreaName" name="depositBankAreaName" value="${bankAcctInfo.depositBankAreaName}" placeholder="开户行区域" type="text" maxlength="128">
                            </c:if>
                        </div>
                        <label for="depositBankAreaId" class="col-sm-2 text-right" hidden="true">开户行所在区域编码：</label>
                        <div class="col-sm-4 text-left" hidden="true">
                            <input onclick="bank();" class="form-control" id="depositBankAreaId" name="depositBankAreaId" value="${bankAcctInfo.depositBankAreaId}" placeholder="开户行所在区域编码" type="text" maxlength="10">
                        </div>
                    </div>
                   
                </div>    
                <div class="box-footer text-center">
                    <c:if test="${!type}">
                         <button type="button" class="btn btn-success btn-sm" onclick="saveBankAcctInfo();">提 交</button>
                    </c:if>
                     <a href="${ctx }/bankAcctInfoLog/toBankAcctInfoLogCore.html?bankAcctId=${bankAcctInfo.bankAcctId}" class="btn btn-success btn-sm">日志查看</a>
                </div>
            </form>
        </div>
    </section>   
    
    
    
    
   <%@ include file="/WEB-INF/component/commonJS.jsp"%>
   <script type="text/javascript">
    //  显示许可证
        function showImg(imgPath) {
            var url = "${ctx}/acctInfo/toImg.html";
            $.HN.dialog.open({
               "id": "showImg",
               "title": "许可证", 
               "url": url, 
               "data": {"imgPath" : imgPath}, 
               "width": 800, 
               "height": 400, 
               "closefunc":function(params) {
                   if (params) {
                       
                   }
               }
           }); 
        }
    
        function selectImg() {
            $('#acctApprovalPicDir').click();
        }
   
    //支行弹窗
       function bank() {
           
           if (!validateBank()) {
               return;
           }
           
            var url = "${ctx}/acctInfo/toSubBankList.html?bankAcctNo=" + $("#depositBank").val();
           $.HN.dialog.open({
               "id": "bank",
               "title": "支行列表", 
               "url": url, 
               "data": {}, 
               "width": 800, 
               "height": 400, 
               "closefunc":function(params) {
                   if (params) {
                       $("#depositBankNo").val(params.bankCode);
                       $("#depositBankName").val(params.bankName);
                       $("#depositBankAreaName").val(params.areaName);
                       $("#depositBankAreaId").val(params.areaCode);
                   }
               }
           }); 
       }
       
     //支行效验
       function validateBank() {
           var depositBank = $.trim($("#depositBank").val());
           if (depositBank == null || depositBank == "") {
               $.HN.message.alert("请选择开户行！", "消息", "warn");
               return false;
           }
           return true;
       }
       
       
     //提交
       function saveBankAcctInfo() {
           if (!validate()) {
               return;
           }
           
           $.HN.message.confirm("确定提交吗？", "提示信息", "确定").on(function(bool) {
               if (bool) {
                   $("#form").ajaxSubmit({ 
                       dataType : "json",
                       timeout: 10000,
                       success : function(result, statusText) {
                           if (result.success) {
                               document.location.reload();
                               $.HN.message.alert("提交成功！", "消息", "success");
                           } else {
                               $.HN.message.alert(result.msg || "提交失败！",  "消息", "error");
                           }
                       }
                   });
               }
           });
       }
     
     
       //提交效验
       function validate() {
           var bankAcctNo = $.trim($("#bankAcctNo").val());
           if (bankAcctNo == null || bankAcctNo == "") {
               $.HN.message.alert("请输入银行账户！", "消息", "warn");
               return false;
           } else if (isNaN(bankAcctNo)) {
               $.HN.message.alert("请输入合法的银行账户！", "消息", "warn");
               return  ;
           }
           
           var acctHolder = $.trim($("#acctHolder").val());
           if (acctHolder == null || acctHolder == "") {
               $.HN.message.alert("请输入开户人！", "消息", "warn");
               return false;
           }
           
           var depositBank = $.trim($("#depositBank").val());
           if (depositBank == null || depositBank == "") {
               $.HN.message.alert("请选择开户行！", "消息", "warn");
               return false;
           }
           
           if ("${bankAcctInfo == null}" == "true") {
               var acctApprovalPicDir = $.trim($("#acctApprovalPicDir").val());
               if (acctApprovalPicDir == null || acctApprovalPicDir == "") {
                   $.HN.message.alert("请上传开户许可证！", "消息", "warn");
                   return false;
               }
           }
           
           var depositBankNo = $.trim($("#depositBankNo").val());
           if (depositBankNo == null || depositBankNo == "") {
               $.HN.message.alert("请选择开户行号！", "消息", "warn");
               return false;
           }
           
           var depositBankName = $.trim($("#depositBankName").val());
           if (depositBankName == null || depositBankName == "") {
               $.HN.message.alert("请选择开户行名！", "消息", "warn");
               return false;
           }
           
           var depositBankAreaName = $.trim($("#depositBankAreaName").val());
           if (depositBankAreaName == null || depositBankAreaName == "") {
               $.HN.message.alert("请选择开户行区域！", "消息", "warn");
               return false;
           }
           
           
           return true;
       }
       
       
       $(document).ready(function(){
           $("#depositBank").change(function(){
               $("#depositBankNo").val("");
               $("#depositBankName").val("");
               $("#depositBankAreaName").val("");
               $("#depositBankAreaId").val("");
           });
       });

   </script>
        
</body>
</html>
